﻿<?php

session_start();

if(empty($_SERVER['HTTP_X_REQUESTED_WITH']) || strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) != 'xmlhttprequest') 
{
	echo '<!DOCTYPE HTML>';
}

require_once "cfg/cfg.php";
require_once "lib/Generic.php";
require_once "lib/xtemplate.class.php";
require_once "controls/c-main.class.php";

$DB = DbSimple_Generic::connect(CS);
$DB->query('SET NAMES UTF8');

$DB->setErrorHandler('databaseErrorHandler');
$DB->setLogger('myLogger');


function myLogger($db, $sql)
{
	$caller = $db->findLibraryCaller();
	$tip = "at ".@$caller['file'].' line '.@$caller['line'];
	Logger::log($tip, print_r($sql, true));
	// Печатаем запрос (конечно, Debug_HackerConsole лучше)
	// echo "<xmp title=\"$tip\">"; print_r($sql); echo "</xmp>";
}


function databaseErrorHandler($message, $info)
{
	if (!error_reporting()) return;
	echo "SQL Error: $message<br><pre>"; 
	print_r($info);
	echo "</pre>";
	exit();
}

$ctrl = new cMain();


$ctrl->Exec();